package com.syx.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.syx.entity.Goods;
import com.syx.service.ShopService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ShopController {
    @Resource
    private ShopService service;

    @RequestMapping("list.do")
    public String list(Model model,
                       String sname,
                       String priceMin,
                       String priceMax,
                       @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum){
        PageHelper.startPage(pageNum,3);
        Map map = new HashMap();
        map.put("sname",sname);
        map.put("priceMin",priceMin);
        map.put("priceMax",priceMax);
        List list = service.list(map);
        PageInfo pageInfo = new PageInfo(list);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("map",map);
        return "list";
    }

    @RequestMapping("dels.do")
    @ResponseBody
    public Object del(String sid){
        int i = service.del(sid);
        return i;
    }

    @RequestMapping("addTo.do")
    public String addTo(){
        return "add";
    }

    //brand
    @RequestMapping("brand.do")
    @ResponseBody
    public Object brand(){
        List list = service.brand();
        return list;
    }

    @RequestMapping("add.do")
    @ResponseBody
    public Object add(Goods goods){
        int i = service.add(goods);
        return i;
    }
}
